Imports System.Data.SqlClient

Friend Class DBConnectLog
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load( _
        ByRef oObject As SQLAutoDocLib.ConnectLog)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"

        sSQL = sSQL & "     [Connect_SPID],"
        sSQL = sSQL & "     [Connect_Status],"
        sSQL = sSQL & "     [Connect_HostName],"
        sSQL = sSQL & "     [Connect_BlockID],"
        sSQL = sSQL & "     [Connect_Command],"
        sSQL = sSQL & "     [Connect_LoginName],"
        sSQL = sSQL & "     [Connect_Current],"
        sSQL = sSQL & "     [Connect_IsHostProcess],"
        sSQL = sSQL & "     [LastDetectDate],"
        sSQL = sSQL & "     [CreateDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     ConnectHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oData.Rows(0)
                oObject.DatabaseID = .Item("DatabaseID")
                oObject.SessionID = .Item("SessionID")

                oObject.Connect_SPID = .Item("Connect_SPID")
                oObject.Connect_Status = .Item("Connect_Status")
                oObject.Connect_HostName = .Item("Connect_HostName")
                oObject.Connect_BlockID = NullToNumber(.Item("Connect_BlockID"))
                oObject.Connect_Command = NullToString(.Item("Connect_Command"))
                oObject.Connect_LoginName = NullToString(.Item("Connect_LoginName"))
                oObject.Connect_Current = .Item("Connect_Current")
                oObject.Connect_IsHostProcess = .Item("Connect_IsHostProcess")

                oObject.LastDetectDate = NullToString(.Item("LastDetectDate"))
                oObject.CreateDate = .Item("CreateDate")
            End With
        End If

        oData.Dispose()
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.ConnectLog)

        Dim sSQL As String = "insert into ConnectHistory ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [SessionID],"

        sSQL = sSQL & "     [Connect_SPID],"
        sSQL = sSQL & "     [Connect_Status],"
        sSQL = sSQL & "     [Connect_HostName],"
        sSQL = sSQL & "     [Connect_BlockID],"
        sSQL = sSQL & "     [Connect_Command],"
        sSQL = sSQL & "     [Connect_LoginName],"
        sSQL = sSQL & "     [Connect_Current],"
        sSQL = sSQL & "     [Connect_IsHostProcess],"

        sSQL = sSQL & "     [LastDetectDate],"
        sSQL = sSQL & "     [CreateDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.DatabaseID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.SessionID) & ","

        sSQL = sSQL & ValueToDBValue(oObject.Connect_SPID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Connect_Status, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Connect_HostName, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Connect_BlockID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Connect_Command, 50) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Connect_LoginName, 50) & ","
        sSQL = sSQL & BooleanToBit(oObject.Connect_Current) & ","
        sSQL = sSQL & BooleanToBit(oObject.Connect_IsHostProcess) & ","

        sSQL = sSQL & ValueToDBValue(oObject.LastDetectDate) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Update(ByRef oObject As SQLAutoDocLib.ConnectLog)

        Dim sSQL As String = "update ConnectHistory set"
        sSQL = sSQL & "     [LastDetectDate]=" & ValueToDBValue(oObject.LastDetectDate)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [id]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.ConnectLog)
        Dim sSQL As String = "delete from ConnectHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
